<?php defined( '_JEXEC' ) or die( 'Restricted access' ); ?>



<?php
    
    $url = JRoute::_("components/com_jquarks/assets/stylesheets/jquarks_style.css");
    $document =& JFactory::getDocument();
    $document->addHeadLink($url, "stylesheet", "rel");
?>

	<?php echo JText::_('SESSION_RESULTS'); ?>


<!-- Score and answers status -->
<?php
    $score = $this->session->score;
    /*$totalScore = $this->totalQuestions - $this->totalInput + $this->inputEvaluated;*/
    $percent = $score * 10 / $this->totalScore;
?>

<div class="box_title_baithi"><?php echo $this->session->title; ?></div> 

<!-- Answers details -->
<?php

     //defining format for evaluated propositions
    $li      = '<li>';
    $eli     = '</li>';
    $ligreen = '<li class="green-li">';
    $corr    = '<span class="li-highlight-green">  ('  . JText::_('GOOD')    . ')</span>';
    $incorr  = '<span class="li-highlight-red">  ('    . JText::_('WRONG')   . ')</span>';
    $omi     = '<span class="li-highlight-orange">  (' . JText::_('OMITTED') . ')</span>';


     $idq = NULL; // contains the actual question id
?>

		<div class="box_title_table">
			<table>
				<tr>
					<th><?php echo JTEXT::_("BEGIN_TIME");?></th>
					<td><?php echo $this->session->started_on; ?></td>
				</tr>
				<tr>
					<th><?php echo JTEXT::_("END_TIME");?></th>
					<td><?php echo $this->session->finished_on; ?></td>
				</tr>
				<tr>
					<th><?php echo JTEXT::_("TOTAL_TIME");?></th>
					<td><?php echo $this->session->spent_time; ?></td>
				</tr>
				<tr>
					<th><?php echo JTEXT::_("SCORE");?></th>
					<td><?php echo (int)$score. " / ". (int)$this->totalScore. " (".(int)($percent*10)."%)";//echo (int)$percent;?></td>
				</tr>
				<tr>
					<th><?php echo JTEXT::_("REPLY_INFO");?></th>
					<td>
						<?php
							if ($percent < 6) {echo (JTEXT::_("LOW_SCORE"));}
							else if ($percent < 9) {echo (JTEXT::_("GOOD_SCORE"));}
							else {echo (JTEXT::_("EXCELLENT_SCORE"));}
						?>
					</td>
				</tr>
			
			</table>
		</div><br />	
<?php
	 $numberOfQuestion = 0;
	 $chan_le = 0;//TUYEN check CHAN - LE to draw color choice selection
	 $strAnswerOfQuestion = "";
     foreach ($this->results as $res) :	 	
?>	 

			

<?php

        // show question statement if this latter doesn't exist
        $idq_temp = $res->question_id;
        if ($idq_temp != $idq)
        {
            
			if ($idq != NULL) {//NULL: avoid the first time
			
?>
							
						</div><!--dapan clearfix-->
					</div><!-- clearfix -->
					<div class="ketquadung">
						<?php echo $strAnswerOfQuestion;?>
					</div>
				</div><!--colum_right_bai-->
			</div><!--box_content_baithi-->
<?php					
			}
			$chan_le = 0; 
			$numberOfQuestion++;    
			$idq = $idq_temp;
			$strAnswerOfQuestion = $res->answerOfQuestion;
?> 
			<div class="box_content_baithi clearfix">
				<div class="colum_left_bai">
					<p class="item_top_bai"><?php echo JTEXT::_("Q")." ".$numberOfQuestion; ?></p>
					<p class="item_under_bai"><?php echo (JTEXT::_("SCORE").": ".$res->score);?></p>
<?php					
					if ($res->status == 1) {//correct answer
?>
						<p class="item_bottom_bai"><?php echo JTEXT::_("TRUE_STATUS");?></p>
<?php
					}
?>				
<?php
					if ($res->status == 0) {//incorrect answer
?>
						<p class="item_bottom_bai item_bottom_bai_add"><?php echo JTEXT::_("FALSE_STATUS");?></p>
<?php
					}
?>	
<?php
					if ((int)$res->status == -2) {//Omit status
?>
						<p class="item_bottom_bai item_bottom_bai_add item_bottom_bai_add_add"><?php echo JTEXT::_("OMIT_STATUS");?></p>
<?php
					}
?>		
					
				</div>	 
				<div class="colum_right_bai">
					<div class="content_cauhoi"><?php echo $res->statement;?></div>
					<div class="clearfix">
						<div class="luatron"><?php echo JHTML::_("SELECT_ANSWER"); ?></div>
						<div class="dapan clearfix">
<?php       
			
        }
		
		
        switch($res->type_id) :
                case 1: // input question
                    echo $li . $res->altanswer. $eli;
                    break;

                case 2: // option question
                    if ($res->answer_id != NULL) // exists in answers
                    {
                        if($res->correct) {//correct
                            if ($chan_le == 0) {
								$chan_le = 1;
							} else {//=1
								$chan_le = 0;
							}
?>								
								<div class="chan clearfix"><input name = "<?php echo $res->answer_id; ?>" checked="checked" disabled="disabled" type="radio" name="a" value="" /><p class="sai active"><samp><?php echo $res->answer ?></samp></p></div>
<?php
							//echo $ligreen . $res->answer . $corr . $eli; 
                        } else {// incorrect
							if ($chan_le == 0) {
								$chan_le = 1;
?>								
								<div class="chan clearfix"><input name = "<?php echo $res->answer_id; ?>" checked="checked"  disabled="disabled" type="radio" name="a" value="" /><p class="sai "><samp><?php echo $res->answer ?></samp></p></div>
<?php
							} else {//=1
								$chan_le = 0;
?>								
								<div class="le clearfix"><input name = "<?php echo $res->answer_id; ?>" checked="checked" disabled="disabled" type="radio" name="a" value="" /><p class="sai "><samp><?php echo $res->answer ?></samp></p></div>
<?php
							}						
							//echo $li . . $incorr . $eli;  
                        }

                    }
                    else
                    {

?>

						
								
								<!--
								<div class="le clearfix"><input type="radio" name="a" value="" /><p class="sai "><samp> c. 540.987.000 d</samp></p></div>
								-->

<?php					
                        if ($res->correct) {//Corect
							if ($chan_le == 0) {
								$chan_le = 1;
							} else {//=1
								$chan_le = 0;
							}
?>								
								<div class="chan clearfix"><input name = "<?php echo $res->answer_id; ?>" disabled="disabled" type="radio" name="a" value="" /><p class="sai active"><samp><?php echo $res->answer ?></samp></p></div>
<?php
                            //echo $ligreen . $res->answer . $eli;
                        } else {//Incorect
							if ($chan_le == 0) {
								$chan_le = 1;
?>								
								<div class="chan clearfix"><input name = "<?php echo $res->answer_id; ?>" disabled="disabled" type="radio" name="a" value="" /><p class="sai "><samp><?php echo $res->answer ?></samp></p></div>
<?php
							} else {//=1
								$chan_le = 0;
?>								
								<div class="le clearfix"><input name = "<?php echo $res->answer_id; ?>" disabled="disabled" type="radio" name="a" value="" /><p class="sai "><samp><?php echo $res->answer ?></samp></p></div>
<?php
							}						
                            //echo $li . $res->answer . $eli;
                        }
                    }
                    break;

                 case 3: //checkbox question
                 case 4: // option as checkbox
                          if($res->correct) {
                              $debut = $ligreen . $res->answer;
                          } else {
                              $debut = $li      . $res->answer;
                          }
                          if (is_null($res->status))
                          {
                              $fin = $eli;
                          }
                          else
                          {
                              switch($res->status)
                              {
                                  case -2: $fin = $eli;           break;
                                  case  0: $fin = $incorr . $eli; break;
                                  case  1: $fin = $corr   . $eli; break;
                                  case  2: $fin = $omi    . $eli; break;
                              }
                          }
                          echo $debut.$fin;
          
        
		 endswitch;
    endforeach;
?>

</div>